"use strict"
$(function(){

    let id = location.search.split('?')[1];

    console.log(id);
    if (id) {
        $.get(`http://localhost:8000/product/${id}`,data=>{
            console.log(data);
            $('[name=id]').val(data.id);
            $('[name=headline]').val(data.headline);
            $('[name=abstract]').val(data.abstract);
            $('[name=details]').val(data.details);
            $('[name=classify]').val(data.classify);
            $('[name=author]').val(data.author);

        })
    }
})
function save(){
    let id = $('[name=id]').val();
    let headline = $('[name=headline]').val();
    let abstract = $('[name=abstract]').val();
    let details = $('[name=details]').val();
    let classify = $('[name=classify]').val();
    let author = $('[name=author]').val();

    let obj = {
        id,
        headline,
        abstract,
        details,
        classify,
        author
    }
    console.log(obj);
    let ob = {
        headline,
        abstract,
        details,
        classify,
        author
    }

    if (obj.id) {
        $.ajax({
            url:'http://localhost:8000/product',
            type:'put',
            data:obj,
            success:(data)=>{
                window.location.href = './index.html'
            }
        })
    }else{

        $.post('http://localhost:8000/product',ob,(data)=>{








            window.location.href = './index.html'
         })
    }

}